package com.tuanzi.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author tuanzi
 * @version 1.0
 * @date 2022/4/25 21:33
 */

public class GetDataFromJson {

    public static Map<String,Float> getData(String payload){
        // 定义一个Map，用来存储键值对
        Map<String,Float> myData = new HashMap<>();

        String replace = payload.replace("{", "");
        String replace1 = replace.replace("}", "");

        // 然后根据,进行分割
        String[] split = replace1.split(",");
        for (String s : split) {
            String[] split1 = s.split(":");

            String s1 = split1[0].replaceAll(" ", "");
            String name = s1.replaceAll("\n", "");

            float data = Float.parseFloat(split1[1]);

            myData.put(name,data);
        }

        return myData;
    }

}
